<!-- html -->
<template>
  <span class="span2">父组件内容：{{ text }}</span>
  <button class="button1" @click="changeParentText">修改内容</button>
  <button class="button1" @click="changeText">父组件修改内容</button>
</template>

<!-- js或ts -->
<script lang="ts">
export default {
  name: 'provideInjectTest1Grandson'
}
</script>

<!-- js或ts -->
<script setup lang="ts">
import { inject } from 'vue'
//数据
//接收属性
let { text, changeText } = inject('parentText', { text: '默认值', changeText: () => { } })
//方法
function changeParentText() {
  text += '-'
  console.log("text：", text)
}
</script>

<!-- 样式 -->
<style scoped></style>